document.ready(function() {
	openLoad();

	var userid = getUrlParam('userid');
	if (userid == null || userid == '') {
		showTip('用户ID异常');
		return;
	}

	setValue('userid', userid);

	var param = {};
    param.ctrl = 'account';
    param.func = 'getOwnerName';
    param.userid = encodeURIComponent(userid);

    sendAjax(param, function(result) {
    	setValue('username', result.username);
        setValue('oldUsername', result.username);

        setDisplay('mainBg', '');
        closeLoad();
    });
});

function editPwd() {
	if (isEmpty('userid')) {
        showTip('用户ID格式错误');
        return;
    }
    if (isEmpty('username')) {
        showTip('用户名格式错误');
        return;
    }
    if (isEmpty('newpassword') || isWicked('newpassword')) {
        showTip('新密码格式错误');
        return;
    }
    if (isEmpty('againpassword') || isWicked('againpassword')) {
        showTip('确认密码格式错误');
        return;
    }
    if (getValue('newpassword') != getValue('againpassword')) {
    	showTip('两次密码输入不一致');
		return;
	}

	var param = {};
    param.ctrl = 'account';
    param.func = 'editPwd';
    param.userid = getAjaxValue('userid');
    param.username = getAjaxValue('username');
    param.oldusername = getAjaxValue('oldUsername');
    param.newpassword = getAjaxValue('newpassword');
    param.againpassword = getAjaxValue('againpassword');

    sendAjax(param, function(result) {
        showTip('修改成功');
        setTimeout('clear()', 1500);
    });
}

function clear() {
    setStorage('user_token', '');
    parent.window.location.href = 'admin.php?m=account&c=login';
}